package AggregationMethod;

import java.util.ArrayList;

import Definitions.NodeClass;
import Global.GlobalClass;
import Sampling.SamplingAbstractClass;


/*****************************************************************
* Name : NeighbourhoodFunction
* Aim : This class aims to keep the mutual functions  between  Neighbourhood Functions and provide a choice method that calls the requested method *
*****************************************************************/
public  abstract class NeighbourhoodFunctionAbstractClass implements AggregationMethodInterface 
{
	String name;
	SamplingAbstractClass currentSampling;
	GlobalClass global;
	
	public NeighbourhoodFunctionAbstractClass(SamplingAbstractClass currentSampling) 
	{
		this.currentSampling = currentSampling;
		this.global = currentSampling.getGlobal();
		// TODO Auto-generated constructor stub
	}
	 /*****************************************************************
	* Function Name: 	countEdge
	* Aim: 				perform the countEdge
	* Inputs: 			ArrayList<Node> node : The neighbors that will be used for the method
	* 					int usePredictOrActual : Predicted Classes or actual classes will be used 
	* 											when choosing neighbors
	* Outputs: 			sumList
	* Data Structures:  ---
	* Algorithms : For example if there are 3 classes and a node has 2 neighbors from class 1 and 1 neighbor from
	* 				class 3 then countEdge method will return this : [2,0,1]*
	*****************************************************************/
	public ArrayList<Double> countEdge(ArrayList<NodeClass> nodeList, int degree)
	{
		
		ArrayList<Double> sumList = new ArrayList<Double>();
		
		int order = -1; 
		
		for (int k = 0; k < global.classList.size(); k++) 
		{
			sumList.add((double)0);
		}
		if(nodeList.size()==0)
		{
			for(int i=0; i< sumList.size() && i< currentSampling.classRatiosOfTrain.size() ;i++)
			{
				sumList.set(i,(currentSampling.classRatiosOfTrain.get(i)));
				
			}
		}
		else 
		{
			for (int k = 0; k < nodeList.size(); k++) 
			{
				if(currentSampling.isTheNodeInTestSetForTheFold(nodeList.get(k)))
				{
					order = currentSampling.getClassLabelEstimated(nodeList.get(k));
				}
				else
				{
					order = nodeList.get(k).getClassOrder();
				}
				if(order != -1)
					sumList.set(order, (sumList.get(order) + 1));				 
			}
		}
		return sumList;
	}

	public ArrayList<Double> countEdge(ArrayList<NodeClass> nodeList)
	{
		ArrayList<Double> sumList = new ArrayList<Double>();
		
		int order = -1; 
		
		for (int k = 0; k < global.classList.size(); k++) 
		{
			sumList.add((double)0);
		}
		if(nodeList.size()==0)
		{			
			for(int i=0; i< sumList.size() ;i++)
			{
				sumList.set(i,(currentSampling.classRatiosOfTrain.get(i)));
			}
		}
		else 
		{
			for (int k = 0; k < nodeList.size(); k++) 
			{
				if(currentSampling.isTheNodeInTestSetForTheFold(nodeList.get(k)))
				{
					order = currentSampling.getClassLabelEstimated(nodeList.get(k));
				}
				else
				{
					order = nodeList.get(k).getClassOrder();
				}
				
				if(order != -1)
					sumList.set(order, (sumList.get(order) + 1));
				 
			}
		}
		return sumList;
	}
	
	@Override
	public ArrayList<Double> getAggregatedNeighbourVector(ArrayList<NodeClass> neighbours) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public ArrayList<Double> getAggregatedNeighbourVector(ArrayList<NodeClass> neighbours, int degree) {
		// TODO Auto-generated method stub
		return null;
	}

}


